<template>
  <div class="main">
    <div style="display: flex; justify-content: center">
      <div class="content">
        <h2 style="text-align: center; margin-bottom: 95px">
          {{ t("登录.标题") }}
        </h2>
        <div class="from">
          <el-tabs v-model="style">
            <el-tab-pane :label="t('登录.使用手机号登陆')" name="1">
              <div class="tabCont">
                <input
                  type="text"
                  v-model="form.phone"
                  :placeholder="t('登录.请输入手机号')"
                />
                <input
                  type="password"
                  v-model="form.phone_password"
                  :placeholder="t('登录.请输入密码')"
                />
                <div class="hint">
                  <router-link to="forget" class="forget">{{
                    t("登录.忘记密码")
                  }}</router-link>
                  <router-link to="register" class="register">{{
                    t("登录.注册")
                  }}</router-link>
                </div>
              </div>
              <button @click="loginBtnClick()">{{ t("登录.登录") }}</button>
            </el-tab-pane>
            <el-tab-pane :label="t('登录.使用邮箱登录')" name="2">
              <div class="tabCont">
                <input
                  type="text"
                  v-model="form.email"
                  :placeholder="t('登录.请输入邮箱账号')"
                />
                <input
                  type="text"
                  v-model="form.email_password"
                  :placeholder="t('登录.请输入密码')"
                />
                <div class="hint">
                  <p class="forget" @click="$router.push('forget')">
                    {{ t("登录.忘记密码") }}
                  </p>
                  <p @click="$router.push('register')" class="register">
                    {{ t("登录.注册") }}
                  </p>
                </div>
              </div>
              <button @click="loginBtnClick()">{{ t("登录.登录") }}</button>
            </el-tab-pane>
            <el-tab-pane :label="t('登录.微信扫码登录')" name="3">
              <div class="tabContCode">
                <img src="" alt="" />
                <p>{{ t("登录.使用微信扫一扫登录") }}</p>
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
        <div class="rests">
          <p>{{ t("登录.其他方式登录") }}</p>
          <img
            src="../../assets/images/home/facelogin.png"
            alt=""
            class="icon"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { smsSend, login } from "@/utils/api.js";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      /**
       * 1：手机注册 2：邮箱注册 3:微信扫码登录
       */
      style: "1",
      form: {
        phone: "",
        phone_password: "",
        email: "",
        email_password: "",
      },
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    /**
     * 简化翻译方法(少写property)
     * @param {String} v 最后一个key值
     */
    t(v) {
      return this.$t(`${v}`);
    },
    loginBtnClick() {
      let data = {};
      if (this.style == "1") {
        if (!this.$util.checkPhone(this.form.phone)) {
          this.$message({
            message: this.t("请输入正确的手机号"),
            type: "error",
          });
          return;
        }
        if (this.form.phone_password.length < 1) {
          this.$message({
            message: this.t("请输入正确的密码"),
            type: "error",
          });
          return;
        }
        data = {
          ...data,
          account: this.form.phone,
          password: this.form.phone_password,
        };
      }

      login(data).then((res) => {
        if (res.code == 1) {
          this.$store.commit("SET_USER", res.data);
          this.$router.replace("/");
          this.$message({
            message: res.msg,
            type: "success",
          });
        }
      });
    },
  },
  beforeCreate() {}, //生命周期 - 创建之前
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  beforeMount() {}, //生命周期 - 挂载之前
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
};
</script>
<style lang="less" scoped>
::v-deep #tab-1 {
  width: 126px !important;
}
::v-deep #tab-2 {
  width: 126px !important;
  margin-left: 10px;
}
::v-deep #tab-3 {
  width: 126px !important;
  margin-left: 10px;
}
::v-deep .el-tabs__active-bar {
  width: 126px !important;
}
a {
  text-decoration: none;
}
.el-tabs {
  width: 420px;
}
.main {
  .content {
    margin-top: 120px;
    width: 500px;
    height: 750px;
    position: relative;

    h2 {
      font-size: 39px;
      font-family: Source Han Sans SC;
      font-weight: bold;
      color: #000000;
      line-height: 99px;
    }

    .from {
      display: flex;
      justify-content: center;

      .tabCont {
        width: 100%;
        display: flex;
        justify-content: center;
        flex-direction: column;
        gap: 40px;
        margin-top: 20px;

        input {
          width: 100%;
          height: 60px;
          background: #f9f9f9;
          border-radius: 10px;
          border: 0px;
          outline: none;
          text-indent: 1em;
        }

        .hint {
          width: 100%;
          height: 40px;
          display: flex;
          justify-content: space-between;
          font-size: 14px;
          font-weight: bold;

          .forget {
            color: #000;
            &:hover {
              cursor: pointer;
            }
          }

          .register {
            color: #ff5757;
            &:hover {
              cursor: pointer;
            }
          }
        }
      }

      .tabContCode {
        width: 373px;
        height: 373px;
        border-radius: 20px;
        background: #f9f9f9;
        margin-left: 20px;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;

        img {
          width: 260px;
          height: 260px;
        }

        p {
          width: 154px;
          height: 14px;
          font-size: 14px;
          font-weight: 400;
          color: #333333;
          margin-top: 15px;
          text-align: center;
        }
      }

      button {
        width: 100%;
        height: 60px;
        background: #ff5757;
        border-radius: 10px;
        color: #fff;
        text-align: center;
        line-height: 40px;
        border: 0px;
        font-size: 18px;
      }
    }

    .rests {
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      position: absolute;
      bottom: 100px;

      p {
        font-size: 16px;
        font-weight: 400;
        color: #999999;
        margin-bottom: 10px;
      }

      img {
        width: 39px;
        height: 39px;
      }
    }

    /deep/ .el-tabs__item.is-active {
      color: #000;
      font-weight: bold;
    }

    /deep/ .el-tabs__item {
      width: 210px;
      color: #666;
      font-size: 16px;
    }

    /deep/ .el-tabs__active-bar {
      background-color: #ff5757;
    }

    /deep/ .el-tabs__item:hover {
      color: #000;
    }
  }
}
</style>
